from django.db import models
from dingxiang.utils.models import BaseModel
from stdimage import StdImageField
from django.utils.safestring import mark_safe

# # 不支持上传文件
# from ckeditor.fields import RichTextField
# # 支持上传文件
# from ckeditor_uploader.fields import RichTextUploadingField

# Create your models here.

# 科室表
class DepartmentModel(BaseModel):
    name = models.CharField(max_length=255, verbose_name="科室名称")

    class Meta:
        db_table = 'department'
        verbose_name_plural = '科室'

    def __str__(self):
        return self.name

# 筛选表
class ScreenModel(BaseModel):
    name = models.CharField(max_length=100,unique=True,verbose_name='筛选名称')
    notes = models.TextField(null=True, blank=True, verbose_name="备注")
    screen_department = models.ManyToManyField(DepartmentModel, null=True, verbose_name='筛选')

    class Meta():
        db_table = "screen"
        verbose_name_plural = '筛选'

# 常见疾病表
class CommonDiseasesModel(BaseModel):
    name = models.CharField(max_length=100, unique=True, verbose_name='疾病名称')
    common_diseases_department = models.ForeignKey(DepartmentModel, on_delete=models.CASCADE, verbose_name='所属科室')
    class Meta():
        db_table = "common_diseases"
        verbose_name_plural = '常见疾病'

# 常见疾病详情表
class Disease(models.Model):
    name = models.CharField(max_length=255, verbose_name="疾病名称")
    code = models.TextField(null=True, verbose_name="简介")
    description = models.TextField(null=True, verbose_name="症状")
    common_symptoms = models.TextField(null=True, verbose_name="病因")
    transmission_routes = models.TextField(null=True, verbose_name="诊断")
    treatment_methods = models.TextField(null=True, verbose_name="治疗")
    prevention_measures = models.TextField(null=True, verbose_name="生活")
    common_medications = models.TextField(null=True, verbose_name="预防")
    common_diseases = models.ForeignKey(CommonDiseasesModel, on_delete=models.DO_NOTHING, null=True, related_name="disease_common_diseases", verbose_name='所属疾病')
    class Meta:
        db_table = 'disease'
        verbose_name_plural = '常见疾病详情'

    def __str__(self):
        return self.name

# 疾病表
class DiseaseArticlesModel(BaseModel):
    recomment_home = models.BooleanField(default=False,verbose_name='是否推荐首页栏目')
    disease_articles_department = models.ForeignKey(DepartmentModel, on_delete=models.CASCADE, verbose_name='所属科室')
    ScreenModels = models.ForeignKey(ScreenModel, null=True, related_name="diseases_articles_screen", on_delete=models.CASCADE, verbose_name='筛选')
    class Meta():
        db_table = "diseases_articles"
        verbose_name_plural = '疾病'

# 疾病文章
class DiseaseArticle(models.Model):
    title = models.CharField(max_length=255, verbose_name="标题")
    code = models.TextField(null=True, blank=True, verbose_name="简介")
    description = models.TextField(null=True, blank=True, verbose_name="症状")
    common_symptoms = models.TextField(null=True, blank=True, verbose_name="病因")
    transmission_routes = models.TextField(null=True, blank=True, verbose_name="诊断")
    treatment_methods = models.TextField(null=True, blank=True, verbose_name="治疗")
    prevention_measures = models.TextField(null=True, blank=True, verbose_name="生活")
    common_medications = models.TextField(null=True, blank=True, verbose_name="预防")
    disease_article = models.ForeignKey(DiseaseArticlesModel, null=True, related_name="disease_article", on_delete=models.CASCADE, verbose_name='疾病文章')

    class Meta:
        db_table = 'disease_article'
        verbose_name_plural = '疾病文章'

    def __str__(self):
        return self.title
